/*
 * Copyright (C) 2011~2012 dinstone <dinstone@163.com>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.dinstone.practice.log;

import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.Logger;

public class JDK14LogTest {

    public static void main(String[] args) {
        Logger logFirst = Logger.getLogger("first");
        // 设置logger级别为null，让logger继承父级别
        // 默认RootLogger的级别为INFO
        logFirst.setLevel(null);

        // 创建一个INFO级别的Handler
        ConsoleHandler handler = new ConsoleHandler();
        handler.setLevel(Level.INFO);

        Logger logMiddle = Logger.getLogger("first.middle");
        // 添加一个INFO级别的Handler
        logMiddle.addHandler(handler);
        logMiddle.setLevel(Level.OFF);

        Logger logMiddleSame = Logger.getLogger("first.middle");
        System.out.println(logMiddle == logMiddleSame); // true

        Logger logLast = Logger.getLogger("first.middle.last");
        logLast.setLevel(Level.INFO);
        // 添加一个INFO级别的Handler
        logMiddle.addHandler(handler);

        logFirst.info("first info");
        logMiddle.info("middle info");

        // logLast的INFO级别的日志输出3遍
        logLast.info("last info");
        logLast.fine("last fine");
    }
}
